<template>
	<view class="page">
		<view class="code-get">
			<view class="code">
				<input type="number"  placeholder="请输入手机号" v-model="phone">
			</view>
			<view class="code">
				<input type="tel" maxlength="6" placeholder="请输入短信验证码" v-model="verify">
				<text class="mo" @click="tui.dianji(get_code)" v-if="djs=='获取验证码'">{{djs}}</text>
				<text class="mo" v-if="djs!='获取验证码'">{{djs}}秒后重试</text>
			</view>
			<view class="code">
				<input type="password"  placeholder="请输入新密码" v-model="password">
			</view>
			<view class="btn" @click="tui.dianji(submite)">
				<text>确认</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isSetting: false,
				phone:'',
				verify:'',
				password:'',
				djs:'获取验证码',
				is_btn:false,
				timer:null
			};
		},
		onLoad() {
			
		},
		methods:{
			get_code(){
				let that = this
				if(that.phone==''){
					that.tui.toast('请输入手机号');
					return;
				}
				if(that.is_btn){return false}
				that.tui.request("api.login/send", "POST",{phone:that.phone} , false, true, true).then((res) => {
					that.djs = 10
					that.is_btn = true
					that.tui.toast('发送成功');
					that.timer=setInterval(function(){
						that.djs--
						if(that.djs==0){
							clearInterval(that.timer)
							that.djs = '获取验证码'
							that.is_btn = false
						}
					},1000)
				}).catch((res) => {})
			},
			submite(){
				let that = this
				if(that.phone==''){
					that.tui.toast('请输入手机号')
					return
				}
				if(that.verify==''){
					that.tui.toast('请输入短信验证码')
					return
				}
				if(that.password==''){
					that.tui.toast('请输入登录密码')
					return
				}
				that.tui.request('api.login/forgetPass', "POST", {phone:that.phone,verify:that.verify,password:that.password}, false, false, true).then((res) => {
					that.tui.toast(res.info)
					if(res.code==1){
						if(that.type==1){
							uni.clearStorageSync()
							setTimeout(function(){
								uni.reLaunch({
									url:'/pages/login/login'
								})
							},1000)
						}else{
							setTimeout(function(){
								uni.navigateBack()
							},1000)
						}
					}
				}).catch((res) => {
					
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	@import 'ChangePassword.scss';
</style>
